#
def webUV():
    file_name = r"C:\Users\15384\Desktop\anishell.cn.log"
    client_ip_list = []
    with open(file_name,mode="r")as fobj:
        for line in fobj:
            client_ip = line.split()[0]
            client_ip_list.append(client_ip)

    for ip in set(client_ip_list):
        print("客户端IP:%s  访问次数：%s" %(ip,client_ip_list.count(ip)))

if __name__ == '__main__':
   webUV()



#----------------正则过滤---------------------------
import re
def webUV1():

    file_name = r"C:\Users\15384\Desktop\anishell.cn.log"
    client_ip_re = r"\b(?:\d{1,3}\.){3}\d{1,3}\b"
    client_ip_list = []

    with open(file_name,mode="r")as fobj1:
        for line in fobj1:
            match_obj = re.search(client_ip_re,line)
            if match_obj:
                client_ip = match_obj.group()
                client_ip_list.append(client_ip)


    for ip in set(client_ip_list):
        print("客户端IP:%s  访问次数：%s" %(ip,client_ip_list.count(ip)))

if __name__ == '__main__':
    webUV1()
